﻿using System.Collections.Generic;
using BruteForce.Animation;
using BruteForce.GameObjects;
using BruteForce.NewManagers;
using BruteForce.Screens.PlayingScreen.Map;
using BruteForce.Screens.PlayingScreen.Panels;
using Bruteforce.Animation;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace BruteForce.Characters {
    public class Archer : Character {
        private ArrowTransition ShootingArrow;

        public Archer(Resources initialResource, bool human, GamePanel gamePanel, Vector2 initialPosition, MapCell mapCell, PlayerType player)
            : base(gamePanel, initialResource, initialPosition, mapCell, player) {
            IsHuman = human;
            AnimationTransition = new LinearFrameAnimationTransition(0,
                                                                     VisualMap[
                                                                         new Key((human ? "Humans" : "Monsters"),
                                                                                 "Archer", "walking", "se")], 0.025);

            ShootingArrow = new ArrowTransition(1);
            ShootingArrow.OnTransitionDone += ShootingArrowOnOnTransitionDone;
            Type = CharacterType.Archer;
        }

        private void ShootingArrowOnOnTransitionDone() {
            GamePanel.Current.AfterShooting(ShootingArrow.StartPosition);
        }


        public void Shoot(Vector2 worldPosition) {
            AnimationTransition.Textures =
                VisualMap[new Key((IsHuman ? "Humans" : "Monsters"), Type.ToString(), "shooting", FindDirections(worldPosition))];
            AnimationTransition.TextureSwitchDuration = 0.08;
            AnimationTransition.StartTransition();
            AnimationTransition.Duration = 1;
            ShootingArrow.StartPosition = WalkingTransition.EndPosition;
            ShootingArrow.EndPosition = worldPosition;
            ShootingArrow.StartTransition();
        }
    }
}